{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\OECD.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}31 Oct 2025, 09:17:32
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data/OECD";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Step 1: 720 financial balance sheets */
> 
> /* Load data */
> 
> u location transact sector measure time Value
>         if regexm(transact,"^SAF(33|331|332|5|51|513|52)LINC$")
>         & sector=="S1"          /* Total economy */
>         & measure=="CXCE"       /* US$ */
>         & inrange(time,$year_min,$year_max)
>         using `directory'/SNA_TABLE720, clear;
{txt}
{com}. drop sector measure;
{txt}
{com}. /* Rename variables */
> 
> rename Value, lower;
{res}{txt}
{com}. /* Fix variables */
> 
> replace transact = regexr(transact,"^SAF","LF");
{txt}(2,128 real changes made)

{com}. replace transact = "LF3LINC" if transact=="LF33LINC";
{txt}(322 real changes made)

{com}. replace transact = "LF3SLINC" if transact=="LF331LINC";
{txt}(287 real changes made)

{com}. replace transact = "LF3LLINC" if transact=="LF332LINC";
{txt}(287 real changes made)

{com}. replace transact = "LF519LINC" if transact=="LF513LINC";
{txt}(250 real changes made)

{com}. recode value (0 = .);
{txt}(43 changes made to {bf:value})

{com}. replace value = . if location=="COL" & transact=="LF3SLINC" & time==2015;
{txt}(1 real change made, 1 to missing)

{com}.         /* Data error */
> 
> /* Save data */
> 
> tempfile SNA_TABLE720;
{txt}
{com}. save `SNA_TABLE720';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000001.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 2: 720R (SNA 2008) financial balance sheets */
> 
> /* Load data */
> 
> u location transact sector measure time Value
>         if location!="EU27_2020"
>         & regexm(transact,"^LF(3|3S|3L|5|51|519|52)LINC$")
>         & sector=="RS1"         /* Total economy */
>         & measure=="CXCE"       /* US$ */
>         & inrange(time,$year_min,$year_max)
>         using `directory'/SNA_TABLE720R, clear;
{txt}
{com}. drop sector measure;
{txt}
{com}. /* Merge 720 financial balance sheets */
> 
> merge 1:1 location transact time using `SNA_TABLE720',
>         nogen;
{res}{txt}{p 0 7 2}
(variable
{bf:transact} was {bf:str9}, now {bf:str10} to accommodate using data's values)
{p_end}

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}           2,608
{txt}{col 9}from master{col 30}{res}           2,511{txt}  
{col 9}from using{col 30}{res}              97{txt}  

{col 5}Matched{col 30}{res}           2,031{txt}  
{col 5}{hline 41}

{com}. /* Rename variables */
> 
> rename location Counterpart;
{res}{txt}
{com}. rename time year;
{res}{txt}
{com}. rename Value outstand;
{res}{txt}
{com}. /* Fix variables */
> 
> recode outstand (0 = .);
{txt}(44 changes made to {bf:outstand})

{com}. /* Convert to US$ billion */
> 
> replace outstand = outstand/1e3;
{txt}(4,498 real changes made)

{com}. /* Extrapolate backward if 720R (SNA 2008) missing and 720 available */
> 
> gsort Counterpart transact -year;
{txt}
{com}. by Counterpart transact: gen Gvalue = value/value[_n-1];
{txt}(2,763 missing values generated)

{com}. by Counterpart transact: replace Gvalue = value[_n+1]/value if missing(Gvalue);
{txt}(207 real changes made)

{com}. by Counterpart transact: replace outstand = outstand[_n-1]*Gvalue if missing(outstand);
{txt}(91 real changes made)

{com}. drop value Gvalue;
{txt}
{com}. /* Merge country code */
> 
> merge m:1 Counterpart using Countries,
>         keepusing(Ynat)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,639{txt}  
{col 5}{hline 41}

{com}. /* Reallocate other equity to fund shares */
> 
> egen other = total(outstand*(trans=="LF519LINC")), missing by(year Counterpart);
{txt}
{com}. replace outstand = outstand-other if transact=="LF51LINC";
{txt}(511 real changes made)

{com}. replace outstand = outstand+other if transact=="LF52LINC";
{txt}(511 real changes made)

{com}. drop if trans=="LF519LINC";
{txt}(554 observations deleted)

{com}. drop other;
{txt}
{com}. /* Construct variables */
> 
> gen byte type = 0 if transact=="LF3LINC";
{txt}(3,371 missing values generated)

{com}. replace type = 1 if transact=="LF3SLINC";
{txt}(652 real changes made)

{com}. replace type = 2 if transact=="LF3LLINC";
{txt}(652 real changes made)

{com}. replace type = 3 if transact=="LF51LINC";
{txt}(674 real changes made)

{com}. replace type = 4 if transact=="LF52LINC";
{txt}(674 real changes made)

{com}. replace type = 5 if transact=="LF5LINC";
{txt}(719 real changes made)

{com}. drop transact;
{txt}
{com}. /* Construct share in common equity and fund shares */
> 
> egen Toutstand = total(outstand) if inlist(type,3,4), missing by(year Counterpart);
{txt}(2,737 missing values generated)

{com}. gen share = outstand/Toutstand if inlist(type,3,4);
{txt}(2,743 missing values generated)

{com}. drop Toutstand;
{txt}
{com}. /* Expand to common equity and fund shares */
> 
> sort year Counterpart type;
{txt}
{com}. by year Counterpart: gen byte obs = type-max(type[_n-1],2) if type==5;
{txt}(3,366 missing values generated)

{com}. expand obs, gen(duplicate);
{txt}(3,366 missing counts ignored; observations not deleted)
(90 observations created)

{com}. bysort year Counterpart type duplicate: replace type = _n+2 if duplicate;
{txt}(90 real changes made)

{com}. drop if type==5;
{txt}(719 observations deleted)

{com}. drop obs;
{txt}
{com}. /* Extrapolate backward */
> 
> gsort Counterpart type -year;
{txt}
{com}. by Counterpart type: replace share = share[_n-1] if missing(share);
{txt}(16 real changes made)

{com}. /* Assume common equity if breakdown unknown */
> 
> replace share = 1 if type==3 & missing(share);
{txt}(40 real changes made)

{com}. drop if type==4 & missing(share);
{txt}(40 observations deleted)

{com}. /* Impute common equity and fund shares from total */
> 
> replace outstand = share*outstand if duplicate;
{txt}(10 real changes made)

{com}. drop share duplicate;
{txt}
{com}. /* Construct share in ST and LT debt */
> 
> egen Toutstand = total(outstand) if inlist(type,1,2), missing by(year Counterpart);
{txt}(2,112 missing values generated)

{com}. gen share = outstand/Toutstand if inlist(type,1,2);
{txt}(2,113 missing values generated)

{com}. drop Toutstand;
{txt}
{com}. /* Expand to ST and LT debt */
> 
> sort year Counterpart type;
{txt}
{com}. by year Counterpart: gen byte obs = min(type[_n+1],3)-type if type==0;
{txt}(2,702 missing values generated)

{com}. expand obs, gen(duplicate);
{txt}(2,702 missing counts ignored; observations not deleted)
(124 observations created)

{com}. bysort year Counterpart type duplicate: replace type = _n if duplicate;
{txt}(124 real changes made)

{com}. drop obs;
{txt}
{com}. /* Extrapolate backward */
> 
> gsort Counterpart type -year;
{txt}
{com}. by Counterpart type: replace share = share[_n-1] if missing(share);
{txt}(24 real changes made)

{com}. /* Impute ST and LT debt from All debt */
> 
> replace outstand = share*outstand if duplicate;
{txt}(124 real changes made, 100 to missing)

{com}. drop share duplicate;
{txt}
{com}. /* Correct rounding error in total */
> 
> egen Toutstand = total(outstand*inlist(type,1,2)), missing by(year Counterpart);
{txt}
{com}. replace outstand = Toutstand if type==0 & Toutstand>0;
{txt}(391 real changes made)

{com}. drop Toutstand;
{txt}
{com}. /* Drop missing data */
> 
> drop if missing(outstand);
{txt}(107 observations deleted)

{com}. /* Drop incomplete data */
> 
> drop if Counterpart=="IND" & type>=3;
{txt}(20 observations deleted)

{com}. /* Keep sample of countries */
> 
> keep if year>=Ynat;
{txt}(1,096 observations deleted)

{com}. drop Ynat;
{txt}
{com}. /* Label variables */
> 
> order year Counterpart type;
{txt}
{com}. label var year                  "Year";
{txt}
{com}. label var Counterpart   "Issuer country by residency";
{txt}
{com}. label var type                  "Asset type";
{txt}
{com}. label var outstand              "Amount outstanding (US$ billion)";
{txt}
{com}. label define type_label
>         0 "All debt"
>         1 "Short-term debt"
>         2 "Long-term debt"
>         3 "Equity"
>         4 "Fund shares";
{txt}
{com}. label val type type_label;
{txt}
{com}. /* Save data */
> 
> compress;
  {txt}variable {bf}{res}Counterpart{sf}{txt} was {bf}{res}str9{sf}{txt} now {bf}{res}str3{sf}
{txt}  (13,902 bytes saved)

{com}. sort year Counterpart type;
{txt}
{com}. save OECD, replace;
{txt}{p 0 4 2}
file {bf}
OECD.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\OECD.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}31 Oct 2025, 09:17:34
{txt}{.-}
{smcl}
{txt}{sf}{ul off}